#include<stdio.h>

long ean_13(long num);
int main(int argc, char *argv[])
{
	long num;
	long ean;

	//检查输入
	do{
		printf("请输入12位数字\n");
		scanf("%ld", &num);
	}while(num >= 1e12 || num < 1e11);
	
	ean = ean_13(num);

	printf("带验证码的条码为：%ld\n", ean);

	return 0;
}

long ean_13(long num){
	long res = 0;//生成的13位校验码
	long num1 = num;
	int arr[13];//按位存储13位校验码
	int sumofo = 0;//奇数位和
	int sumofe = 0;//偶数位和
	int addoe;// 奇数和 和 偶数和的三倍 之和
	
	//将num存进数组
	for(int i = 11; i >= 0; i--){//大端存储
		arr[i] = num1%10;
		num1 /= 10;
	}
	
	//计算奇数和 和 偶数和
	for(int i = 0; i <= 11;i++){
		if(0 == (i+1)%2){
			sumofe += arr[i];
		}else{
			sumofo += arr[i];
		}
	}
	addoe = sumofo + 3 * sumofe;
	arr[12] = (addoe%10) ? 10 - (addoe%10) : 0;

	
	for(int i = 0; i <= 12; i++){
		res = res *10 + arr[i];
	}


	return res;
}
 
